package com.example.p2pinvest.fragment;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.shapes.Shape;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.appcompat.widget.DrawableUtils;

import com.example.p2pinvest.R;
import com.example.p2pinvest.common.BaseFragment;
import com.example.p2pinvest.ui.FlowLayout;
import com.example.p2pinvest.util.DrawUtils;
import com.example.p2pinvest.util.UIUtils;
import com.loopj.android.http.RequestParams;

import java.util.Random;

import butterknife.BindView;

/**
 * @author h2tc01
 * @version 1.0.0
 * 2022/8/10
 * 热门理财
 */
public class ProductHotFragment extends BaseFragment {

    @BindView(R.id.flow_hot)
    FlowLayout flowHot;

    private String[] datas = new String[]{"新手福利计划", "财神道90天计划", "硅谷计划",
            "30天理财计划", "180天理财计划", "月月升", "中情局投资商业经营", "大学老师购买车辆",
            "屌丝下海经商计划", "美人鱼影视拍摄投资", "Android培训老师自己周转", "养猪场扩大经营",
            "旅游公司扩大规模", "摩托罗拉洗钱计划", "铁路局回款计划", "屌丝迎娶白富美计划"
    };


    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        for (String data : datas) {
            TextView tv = new TextView(getContext());

            tv.setText(data);
            tv.setTextSize(UIUtils.dp2px(6));  //字体大小
            //外边距
            ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.rightMargin = UIUtils.dp2px(5);
            params.leftMargin = UIUtils.dp2px(5);
            params.topMargin = UIUtils.dp2px(5);
            params.bottomMargin = UIUtils.dp2px(5);
            tv.setLayoutParams(params);

            //内边距
            int padding = UIUtils.dp2px(5);
            tv.setPadding(padding, padding, padding, padding);

            //设置背景
            Random random = new Random();
            int red = random.nextInt(211);
            int green = random.nextInt(211);
            int blue = random.nextInt(211);
            //设置单一背景
            //tv.setBackground(DrawUtils.getDrawable(Color.rgb(red, green, blue), UIUtils.dp2px(5)));

            //设置具有选择器功能的背景
            tv.setBackground(DrawUtils.getSelector(DrawUtils.getDrawable(Color.rgb(red, green, blue), UIUtils.dp2px(5)),
                    DrawUtils.getDrawable(Color.WHITE, UIUtils.dp2px(5))));
            //点击事件
            tv.setOnClickListener(v -> {
                UIUtils.toast(tv.getText().toString(), false);
            });
            flowHot.addView(tv);
        }
    }

    @Override
    protected void initTitle() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_producthot;
    }

}
